#include <pthread.h>
#include <bits/stdc++.h>
using namespace std;

//为了方便控制锁，做一个简单封装


class LockGuard
{
private:
    pthread_mutex_t*_mutex;

public:
    LockGuard(pthread_mutex_t &mutex);
    LockGuard(pthread_mutex_t *mutex);
    ~LockGuard();
};

LockGuard::LockGuard(pthread_mutex_t &mutex)
:_mutex(&mutex)
{
    pthread_mutex_lock(_mutex);
}

LockGuard::LockGuard(pthread_mutex_t *mutex)
:_mutex(mutex)
{
    pthread_mutex_lock(_mutex);
}

LockGuard::~LockGuard()
{
    pthread_mutex_unlock(_mutex);
}
